package com.tencent.wework.list.easy

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

/**
 * Created by huangwei on 2019/5/28.
 */
abstract class EasyViewModel<DATA>:ViewModel(){

    protected val repository:EasyRepository<DATA> by lazy {
        initEaysRepository()
    }

    val data = MutableLiveData<EasyDataWrapper<DATA>>()

    abstract fun initEaysRepository():EasyRepository<DATA>

    fun requestData(){
        repository.requestData {
            data.postValue(EasyDataWrapper(it,false))
        }
    }

    fun loadMoreData(offset:Any?){
        repository.loadMoreData(offset) {
            data.postValue(EasyDataWrapper(it,true))
        }
    }
}